
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    box:1,
    name:'资产',
    num:3,
    NowPmNum:0,
    NowZcNum:0,
    PmMaxNum:0,
    ZcMaxNum:0,
    PMlist:[],
    ZClist:[],
    BJlist:[],
    IsQx:0,
    keytishi:false,
    hqtishi:false
  },
  /**
   * 更改状态并改变view页的提示语
   * @param  {[type]} r [description]
   * @return {[type]}   [description]
   */
  change:function (r) {
    var status = r.currentTarget.dataset.sta;
    if (this.data.IsQx == 0 && status == 3) {
       this.setData({
        hqtishi:true
       }) 
       return false
    }    
    var box = this.data.box;
      if (box != status) {
        if (status == 1) {
          this.setData({
            box:status,
            name:'资产',
            num:this.data.ZcMaxNum
          })           
        }
        if (status == 2) {
          this.setData({
            box:status,
            name:'拍卖',
            num:this.data.PmMaxNum
          })           
        }
        if (status == 3) {
          this.setData({
            box:status,
            name:'报价',
            num:this.data.PmMaxNum
          })           
        }        
      }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.type) {
      this.setData({
        box:options.type 
      })
    }
    this.getKeyList();
    this.getFeijiu_Get_BjDyKeyList();
  },

  getKeyList:function () {
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid:FjLoginLog.UID 
    }
    app.getDaoPostN('api/FeijiuApp/Feijiu_Get_DingYueList146',api_input,function (r) {
     
      that.setData({

        NowPmNum:r.data.NowPmNum,
        NowZcNum:r.data.NowZcNum,
        PmMaxNum:r.data.PmMaxNum,
        ZcMaxNum:r.data.ZcMaxNum,
        PMlist:r.data.PM,
        ZClist:r.data.ZC
      })
    })
  },
  /**
   * 判断当前帐户是否有权限访问行情报价IsQx = 1时可以
   * @return {[type]} [description]
   */
  getFeijiu_Get_BjDyKeyList:function () {
    var that = this;    
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var api_input = {
      uid:FjLoginLog.UID 
    }
    app.getDaoPostN('api/FeijiuApp/Feijiu_Get_BjDyKeyList',api_input,function (r) {
     
      if (r.data.IsQx == 1) {
        that.setData({
          BJlist:r.data.data
        })
      }
      that.setData({
        IsQx:r.data.IsQx
      })      
    })    
  },   
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 关键词用完时弹出层取消
   * @return {[type]} [description]
   */
  quxiaopop:function () {
    this.setData({
      keytishi:false
    })
  },
  /**
   * 没有权限点击行情报价时取消
   * @return {[type]} [description]
   */
  quxiaohq:function () {
    this.setData({
      hqtishi:false
    })
  },
  /**
   * 空操作
   * @return {[type]} [description]
   */
  none:function () {
    // body...
  },
  /**
   * 拨打客服电话
   * @return {[type]} [description]
   */
  fuwudianhua:function(){
    wx.makePhoneCall({
      phoneNumber: '0311-87106666'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      shuaxin:true
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 取消订阅
   * @param  {[type]} e [description]
   * @return {[type]}   [description]
   */
  quxiao:function (e) {

    var that = this;
    wx.showModal({
      title: '尊敬的用户',
      content: '您是否要取消订阅',
      success (res) {
        if (res.confirm) {
          var FjLoginLog = wx.getStorageSync('FjLoginLog');
          var api_input = {
            Uid:FjLoginLog.UID,
            ID:e.currentTarget.dataset.id,
            strRSA:app.data.strRSA
          }
          app.getDaoPostOld('api/FeijiuApp/PostCanCelDingYue',api_input,function (r) {
            if (r.code == 200) {
              if (e.currentTarget.dataset.type == 'zc') {
                that.data.ZClist.splice(e.currentTarget.dataset.idx,1);
                that.setData({
                  ZClist:that.data.ZClist
                })                
              }
              if (e.currentTarget.dataset.type == 'pm') {
                that.data.PMlist.splice(e.currentTarget.dataset.idx,1);
                that.setData({
                  PMlist:that.data.PMlist
                })                 
              }
              app.tishi('删除关键字成功!');
            }
          })
        } 
      }
    })
  },
  /**
   * 根据box值来增加关键字,并判断是否关键词够用,不够用弹出提示
   */
  addKeyWord:function () {
    if (this.data.box == 1 ) {
      if (this.data.ZcMaxNum-this.data.ZClist.length > 0) {
        wx.navigateTo({
          url: 'editkey?type='+this.data.box+'&isgai=0'
        })         
      }else{
        this.setData({
          keytishi:true
        })        
      }
    }
    if (this.data.box == 2 ) {
      if (this.data.PmMaxNum-this.data.PMlist.length > 0) {
        wx.navigateTo({
          url: 'editkey?type='+this.data.box+'&isgai=0'
        })         
      }else{
        this.setData({
          keytishi:true
        })        
      }
    }
    if (this.data.box == 3) {
      wx.navigateTo({
        url: 'editkey?type='+this.data.box+'&isgai=0'
      })         
    }
  },
  editkey:function (e) {
    if (this.data.box == 1) {
      var key = this.data.ZClist[e.currentTarget.dataset.idx];           
    }
    if (this.data.box == 2) {
      var key = this.data.PMlist[e.currentTarget.dataset.idx];           
    }
    if (this.data.box == 3) {
      var key = this.data.BJlist[e.currentTarget.dataset.idx];           
    }        
    wx.setStorageSync('zcdykey',key); 
    wx.navigateTo({
      url: 'editkey?type='+this.data.box+'&isgai=1'
    })    
  }
})